package util.android.widgets;

import util.android.ViewUtil;
import util.android.form.respuesta.NumberPickerInput;

import com.androidutil.R;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.NumberPicker;
import android.widget.TextView;

public class NumberPickerView 
extends AbstractView1<NumberPickerInput,NumberPickerView>
{
	private TextView tvTexto;
	
	public NumberPickerView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	@Override
	protected NumberPickerInput crearInput_agregarVistas() {
		LinearLayout ly = (LinearLayout)View.inflate(getContext(), R.layout.view_number_picker, null);
		NumberPicker npValor = (NumberPicker) ly.findViewWithTag("picker");		
		NumberPickerInput inValor = new NumberPickerInput( npValor );
		inValor.setSoloLectura(false);
		
		tvTexto = (TextView) ly.findViewWithTag("texto");
		tvTexto.setEnabled(false);
		
		//this.getLayoutRespuesta().addView(inValor.getView());
		ViewUtil.addViewWrap_Wrap(this.getLayoutRespuesta(), ly);
		
		return inValor;
	}
	
	
		
	@Override
	protected void procesarAtributosPersonalizados(Context context, AttributeSet attrs) {
		super.procesarAtributosPersonalizados(context, attrs);		
		TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.AbstractView, 0, 0);
		try {
			String text = ta.getString(R.styleable.AbstractView_texto);
			if(text==null || text.trim().isEmpty())
				tvTexto.setVisibility(View.GONE);
			else
				tvTexto.setText(text);
	    } finally {
	        ta.recycle();
	    }		
	}

	@Deprecated
	public NumberPickerView setEtiquetaId_Valor(int etiquetaID, String valor) throws Exception {
		setEtiquetaByStringId(etiquetaID)
		.getInput().setValor(valor);
		return this;
	}
	


	
	

}
